package the.lb.workbench.auth.shiro.factory;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.DependsOn;
import org.springframework.stereotype.Service;
import org.wisteria.framework.web.SpringContextHolder;
import the.broccoli.uc.entity.User;
import the.broccoli.uc.service.IUserService;
import the.lb.workbench.auth.po.AuthUser;

@Service
@DependsOn("springContextHolder")
public class DataFactory implements IData {

    @Autowired
    private IUserService userService;

    /**
     * 根据账号获取登录用户
     *
     * @param account 账号
     */
    @Override
    public User user(String account) {
        return userService.getByAccount(account);
    }

    /**
     * 根据系统用户获取 AuthUser 的用户
     *
     * @param user 系统用户
     */
    @Override
    public AuthUser authUser(User user) {
        AuthUser authUser = new AuthUser();
        authUser.setUserId(user.getUserId());
        authUser.setAccount(user.getAccount());
        authUser.setUserName(user.getUserName());

        return authUser;
    }

    public static IData me() {
        return SpringContextHolder.getBean(IData.class);
    }
}
